package sf.database.template.freemarker.ext;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import sf.database.template.TemplateConstants;
import sf.database.template.freemarker.FreemarkerHelp;

import java.io.IOException;
import java.util.Map;

public class PageIgnoreDirective implements TemplateDirectiveModel {

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
        Map map = (Map) FreemarkerHelp.getRootDataModel(env);
        Boolean bool = (Boolean) map.get(TemplateConstants.SQL_COUNT_KEY);
        if (bool == null || !bool) {
            body.render(env.getOut());
        }
    }
}
